$(function() {
	//获取账户id
	loading();
	var aId = getQueryString("aId");
	ajaxqueryBankCardOne(aId);
	//获取用户信息
	var user=getUser_C();
	if(user){
		$("#balance_").text(user.balance);
		get_telnum_util(user.mobile);
	}
});

/**
 * 加载一张银行卡的详细信息
 * @param accountId	账户id 对应一张银行卡
 * @returns
 */
function ajaxqueryBankCardOne(accountId){
	var url="/Lvscore_User_M/account/ajaxqueryBankCardOne";
	$.post(
		url,
		{'accountId' : accountId},
		function(data){
			console.log(data.userAccount.bankName);
			$("#accId").val(data.userAccount.id);
			$("#img_c").html('<img src="'+getImgSrc(data.userAccount.bankName)+'" alt="" title="" style="margin:10px 0px 10px 20px;">');
			$("#card_type").text(getAccountType(data.userAccount.accountType));
			$("#card_num").text(data.showAccountNum);
			$("#create_time").text(data.userAccount.createTime);
			$(".loadingBox").hide();
		},
		"json");}

function getAccountType(t) {
	if (t == '0')
		return '信用卡';
	else if (t == '1')
		return '储蓄卡';
	else
		return '其他类型';
}

function get_telnum_util(tel) {
	if (tel.length == 11) {
		var first = tel.substring(0, 3);
		var last = tel.substring(7, 11);
		$("#tel_num").text(first + "****" + last);
	}
}

function changePhone() {
	window.location.href = '/Lvscore_User_M/userWeb/views/accounterCenter/changeTel.html';
}

function cancelCard() {
	$('.confirmBox').show();
	$(".mask").show();
	$(".cancle").click(function(){
		$(".mask").hide();
		$(".confirmBox").hide();
	});
	$(".sure").click(function(){
		$(".mask").hide();
		$(".confirmBox").hide();
		ajaxcancelBanding($("#accId").val());
	})
}

function outBlance() {
	window.location.href = '/Lvscore_User_M/userWeb/views/ADadmin/accounterMoney/bankTransfer.html?aId=' + $('#accId').val();
}

/**
 * 解除与已有银行卡的绑定
 * @param accountId	账户id 对应一张银行卡
 * @returns
 */
function ajaxcancelBanding(accountId){
	var url="/Lvscore_User_M/account/ajaxcancelBanding";
	$.post(
		url,
		{'accountId' : accountId},
		function(data){
			if (data == '1')
			{   history.go(-1);
                //$(".statue").text("已解除");
			}
			else if (data == '-1')
			{alertBox('解绑失败',"");}
			else
			{alertBox('服务器异常',"");}
		},
		"json"
	);
}

function getImgSrc(str) {
	if (str == "中国建设银行") {
		return '/Lvscore_User_M/userWeb/static/images/constructionBank_01.png';
	} else if (str == "中国邮政储蓄银行") {
		return '/Lvscore_User_M/userWeb/static/images/chinaEmail_01.png';
	} else if (str == "中国银行") {
		return "/Lvscore_User_M/userWeb/static/images/bankOfChina_01.png";
	} else if (str == "招商银行") {
		return "/Lvscore_User_M/userWeb/static/images/merchants_01.png";
	} else if (str == "浦发银行") {
		return "/Lvscore_User_M/userWeb/static/images/SPDbannk_01.png";
	} else if (str == "中国农业银行") {
		return "/Lvscore_User_M/userWeb/static/images/agriculturalBank_01.png";
	} else if (str == "中国工商银行") {
		return "/Lvscore_User_M/userWeb/static/images/business_01.png";
	} else if (str == "中信银行") {
		return "/Lvscore_User_M/userWeb/static/images/CITICbank_01.png";
	} else if (str == "兴业银行") {
		return "/Lvscore_User_M/userWeb/static/images/xingye.png";
	}else if (str == "平安银行") {
		return "/Lvscore_User_M/userWeb/static/images/safety_01.png";
	}
}